package org.datedemo;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;

public class LocalDateTime2 {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        //秒
        long m1 = now.atZone(ZoneOffset.systemDefault()).toEpochSecond();
        System.out.println(m1);

        //毫秒 在LocalDateTime对象上获取毫秒
        long m2 = now.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli();
        System.out.println(m2);

        //转换为Date
        Date d = new Date(m2);
        System.out.println(d);
        System.out.println(d.getTime());

        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(m2);
        System.out.println(c.getTimeInMillis());
        System.out.println(c.getTime().getTime());
        //转换为Date
        Date d2 = c.getTime();

        //毫秒
        System.out.println(System.currentTimeMillis());
    }
}
